<?php

// +----------------------------------------------------------------------
// | author: admin
// +----------------------------------------------------------------------

namespace app\adminapi\lists\travel;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSortInterface;
use app\common\model\travel\Line;
use app\common\lists\ListsSearchInterface;
use app\common\model\user\User;


/**
 * Line列表
 * Class LineLists
 * @package app\adminapi\liststravel
 */
class LineLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author admin
     * @date 2025/04/25 10:24
     */
    public function setSearch(): array
    {
        return [
            'like' => ['title'],
            '=' => ['travel_agency_id', 'is_hot', 'status'],
        ];
    }


    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author admin
     * @date 2025/04/25 10:24
     */
    public function lists(): array
    {
        if(!empty($this->adminInfo['role_id']) && in_array(3,array_values($this->adminInfo['role_id'])))
        {
           $travel_agency  = User::where('account', $this->adminInfo['account'])->value('travel_agency_id');
           $this->searchWhere['travel_agency_id'] = $travel_agency;
        }
        return Line::where($this->searchWhere)
            ->append(['travel_agency_name', 'is_hot_value', 'status_value','status_remark','user_account','pending_status'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }

    /**
     * @notes  设置支持排序字段
     * @return array
     */
    public function setSortFields(): array
    {
        return ['create_time' => 'create_time', 'id' => 'id'];
    }

    /**
     * @notes  设置默认排序
     * @return array
     */
    public function setDefaultOrder(): array
    {
        return [ 'id' => 'desc'];
    }

    /**
     * @notes 获取数量
     * @return int
     * @author admin
     * @date 2025/04/25 10:24
     */
    public function count(): int
    {
        return Line::where($this->searchWhere)->count();
    }

}